#include <stdio.h>
#include <stdlib.h>
#include "lcv/bmp.h"
#include "lcv/dip.h"
#include "config.h"

void test_bmp()
{
	int i;
	
	printf("reading bmp... ");
	fflush(stdout);
	lcv_picture p_from_bmp = lcv_read_bmp(FULLSIZE_INPUT_IMAGE);
	printf("ok\n");	
	
	printf("writing bmp... ");
	fflush(stdout);
	lcv_write_bmp(p_from_bmp, "bmp_test.bmp");
	printf("ok\n");	
	
	printf("comparing the images... ");
	fflush(stdout);
	lcv_picture p_from_bmp2 = lcv_read_bmp("bmp_test.bmp");
	
	if(p_from_bmp2.length == p_from_bmp.length && 
	   p_from_bmp2.width  == p_from_bmp.width && 
	   p_from_bmp2.height == p_from_bmp.height && 
	   p_from_bmp2.type   == p_from_bmp.type){
	   
	   for(i=0; i<p_from_bmp.length; i++){
	   	if(p_from_bmp2.data[i] != p_from_bmp.data[i]){
	   		printf("\nError: images are not equal\n");
			printf("Aborting Test\n");
			exit(-1);
	   	}
	   }
	   
	}else{
		printf("\nError: images-parameters are not equal\n");
		printf("Aborting Test\n");
		exit(-1);
	}
		
	printf("ok\n");	
	
	lcv_free_picture(&p_from_bmp);
	lcv_free_picture(&p_from_bmp2);
	
}
